export default class selectScene extends Laya.Script {

    constructor() { super(); }
    private return_btn: Laya.Button       //返回主界面按钮
    private rank2_btn: Laya.Button         //排行榜按钮
    private select_panel: Laya.Sprite      //选择面板
    private custom_1: Laya.Sprite          //选择关卡1
    private custom_2: Laya.Sprite          //选择关卡2
    private custom_3: Laya.Sprite          //选择关卡3
    private custom_4: Laya.Sprite          //选择关卡4
    private custom_5: Laya.Sprite          //选择关卡5
    private aniDuration: number            //Tween动画时长

    onEnable(): void {
        //初始化变量
        this.initParams()
        //入场动画
        this.enterAni()
        //初始化绑定事件
        this.initEvent()
    }

    /**初始化绑定点击事件 */
    initEvent() {
        //给返回按钮1绑定事件
        this.return_btn.on(Laya.Event.CLICK, this, this.onReturn)
        //给排行榜按钮绑定事件
        this.rank2_btn.on(Laya.Event.CLICK, this, this.onRank)
        //给选择关卡1绑定点击事件
        this.custom_1.on(Laya.Event.CLICK, this, this.onCustom_1)
        //给选择关卡2绑定点击事件
        this.custom_2.on(Laya.Event.CLICK, this, this.onCustom_2)
        //给选择关卡3绑定点击事件
        this.custom_3.on(Laya.Event.CLICK, this, this.onCustom_3)
        //给选择关卡4绑定点击事件
        this.custom_4.on(Laya.Event.CLICK, this, this.onCustom_4)
        //给选择关卡5绑定点击事件
        this.custom_5.on(Laya.Event.CLICK, this, this.onCustom_5)
    }

    onReturn() {
        Laya.Scene.open("mainScene.scene")
    }

    onRank() {
        Laya.Scene.open("rank_scene.scene")
    }

    onCustom_1() {
        Laya.Scene.open("gameScene1.scene")
        Laya.SoundManager.stopMusic()
    }

    onCustom_2() {
        Laya.Scene.open("gameScene2.scene")
        // Laya.SoundManager.stopMusic()
    }

    onCustom_3() {
        Laya.Scene.open("gameScene3.scene")
        // Laya.SoundManager.stopMusic()
    }

    onCustom_4() {
        Laya.Scene.open("gameScene4.scene")
        // Laya.SoundManager.stopMusic()
    }

    onCustom_5() {
        Laya.Scene.open("gameScene5.scene")
        // Laya.SoundManager.stopMusic()
    }
    /**入场动画 */
    enterAni() {
        Laya.Tween.from(
            this.return_btn,
            { x: 1500 },
            this.aniDuration,
            Laya.Ease.strongInOut
        )

        Laya.Tween.from(
            this.rank2_btn,
            { x: -1000 },
            this.aniDuration,
            Laya.Ease.strongInOut
        )
    }

    /**初始化变量 */
    initParams() {
        //动画时长 
        this.aniDuration = 550
        //获取return1按钮节点(返回主界面)
        this.return_btn = this.owner.getChildByName('return_btn') as Laya.Button
        //排行榜按钮
        this.rank2_btn = this.owner.getChildByName('rank_btn') as Laya.Button
        //选择面板
        this.select_panel = this.owner.getChildByName('select_panel') as Laya.Sprite
        //选择关卡1
        this.custom_1 = this.select_panel.getChildByName('custom_1') as Laya.Sprite
        //选择关卡2
        this.custom_2 = this.select_panel.getChildByName('custom_2') as Laya.Sprite
        //选择关卡3
        this.custom_3 = this.select_panel.getChildByName('custom_3') as Laya.Sprite
        //选择关卡4
        this.custom_4 = this.select_panel.getChildByName('custom_4') as Laya.Sprite
        //选择关卡5
        this.custom_5 = this.select_panel.getChildByName('custom_5') as Laya.Sprite
    }

    onDisable(): void {
    }
}